package com.zyl.util;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class UrlUtil {
	public static String getAgTD() {

		String str = "";
		HttpURLConnection conn = null;
		String loginUri = "http://hq.sinajs.cn/list=SGE_AGTD";
		try {
			URL url = new URL(loginUri);

			conn = (HttpURLConnection) url.openConnection();
			conn.setInstanceFollowRedirects(true);
			conn.setConnectTimeout(3000);
			conn.setRequestProperty("Charset", "GBK");
			conn.connect();
			if (conn.getResponseCode() == HttpURLConnection.HTTP_OK
					&& conn.getContentLength() > 0) {

				InputStream localInputStream = conn.getInputStream();
				BufferedInputStream bufferedInputStream = new BufferedInputStream(
						localInputStream);
				InputStreamReader inputStreamReader = new InputStreamReader(
						bufferedInputStream, "GBK");

				BufferedReader reader = new BufferedReader(inputStreamReader);

				str = reader.readLine();
				reader.close();
				bufferedInputStream.close();
				inputStreamReader.close();
				bufferedInputStream.close();
				localInputStream.close();
			}
		} catch (MalformedURLException e) {

			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {

			e.printStackTrace();
		} catch (IOException e) {

			e.printStackTrace();
		}
		return str;
	}

}
